<template>
    <el-dialog
            :title="!dataForm.infoId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="用户信息ID，主键" prop="infoId">
                        <el-input v-model.number="dataForm.infoId" placeholder="用户信息ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="用户ID，关联用户表" prop="userId">
                        <el-input v-model.number="dataForm.userId" placeholder="用户ID，关联用户表"></el-input>
                </el-form-item>
                <el-form-item label="真实姓名" prop="realName">
                        <el-input v-model="dataForm.realName" placeholder="真实姓名"></el-input>
                </el-form-item>
                <el-form-item label="身份证号码" prop="idCard">
                        <el-input v-model="dataForm.idCard" placeholder="身份证号码"></el-input>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                        <el-input v-model="dataForm.address" placeholder="地址"></el-input>
                </el-form-item>
                <el-form-item label="所在部门（政府部门工作人员）" prop="department">
                        <el-input v-model="dataForm.department" placeholder="所在部门（政府部门工作人员）"></el-input>
                </el-form-item>
                <el-form-item label="公司名称（企业用户）" prop="companyName">
                        <el-input v-model="dataForm.companyName" placeholder="公司名称（企业用户）"></el-input>
                </el-form-item>
                <el-form-item label="第三方机构名称（第三方机构用户）" prop="thirdPartyName">
                        <el-input v-model="dataForm.thirdPartyName" placeholder="第三方机构名称（第三方机构用户）"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                        <el-date-picker
                                v-model="dataForm.createTime"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updateTime">
                        <el-date-picker
                                v-model="dataForm.updateTime"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            infoId: null,
            userId: null,
            realName: null,
            idCard: null,
            address: null,
            department: null,
            companyName: null,
            thirdPartyName: null,
            createTime: null,
            updateTime: null
          },
          dataRule: {
            infoId: [
                        { required: true, message: '用户信息ID，主键不能为空', trigger: 'blur' }
            ],
            userId: [
                        { required: true, message: '用户ID，关联用户表不能为空', trigger: 'blur' }
            ],
            realName: [
                        { required: true, message: '真实姓名不能为空', trigger: 'blur' }
            ],
            idCard: [
                        { required: true, message: '身份证号码不能为空', trigger: 'blur' }
            ],
            address: [
                        { required: true, message: '地址不能为空', trigger: 'blur' }
            ],
            department: [
                        { required: true, message: '所在部门（政府部门工作人员）不能为空', trigger: 'blur' }
            ],
            companyName: [
                        { required: true, message: '公司名称（企业用户）不能为空', trigger: 'blur' }
            ],
            thirdPartyName: [
                        { required: true, message: '第三方机构名称（第三方机构用户）不能为空', trigger: 'blur' }
            ],
            createTime: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ],
            updateTime: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.infoId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.infoId = id || 0
            if (this.dataForm.infoId) {
              this.$http({
                url: this.$http.adornUrl(`/app/user_info/info/${this.dataForm.infoId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appuserinfo
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/user_info/${!this.dataForm.infoId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>